﻿<EditForm Model="@TestModel" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
    <DataAnnotationsValidator />

    <BitCheckbox IsEnabled="@IsEnabled"
                 AriaLabel="@AriaLabel"
                 CheckIconName="@CheckIconName"
                 AriaDescription="@AriaDescription"
                 AriaLabelledby="@AriaLabelledby"
                 AriaPositionInSet="@AriaPositionInSet"
                 AriaSetSize="@AriaSetSize"
                 Name="@Name"
                 Title="@Title"
                 DefaultValue="@DefaultValue"
                 @bind-Value="@TestModel.Value"
                 CheckIconAriaLabel="@CheckIconAriaLabel"
                 Reversed="@Reversed"
                 DefaultIndeterminate="@DefaultIndeterminate"
                 OnClick="HandleOnClick"
                 OnChange="HandleOnChange">
        <ChildContent>
            @ChildContent
        </ChildContent>
    </BitCheckbox>

</EditForm>

@code {
    [Parameter] public bool IsEnabled { get; set; }
    [Parameter] public bool IsIndeterminate { get; set; }
    [Parameter] public string? AriaLabel { get; set; }
    [Parameter] public string? CheckIconName { get; set; }
    [Parameter] public string? CheckIconAriaLabel { get; set; }
    [Parameter] public string? AriaDescription { get; set; }
    [Parameter] public string? AriaLabelledby { get; set; }
    [Parameter] public int? AriaPositionInSet { get; set; }
    [Parameter] public int? AriaSetSize { get; set; }
    [Parameter] public string? Name { get; set; }
    [Parameter] public string? Title { get; set; }
    [Parameter] public bool Reversed { get; set; }
    [Parameter] public bool? DefaultValue { get; set; }
    [Parameter] public bool? DefaultIndeterminate { get; set; }
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public BitCheckboxTestModel TestModel { get; set; } = new();

    public int ClickCounter { get; set; }
    public bool ValueChanged { get; set; }
    public int ValidCount { get; set; }
    public int InvalidCount { get; set; }

    public void HandleOnClick(MouseEventArgs args)
    {
        ClickCounter++;
    }

    public void HandleOnChange(bool value)
    {
        ValueChanged = true;
    }

    private void HandleValidSubmit()
    {
        ValidCount++;
    }

    private void HandleInvalidSubmit()
    {
        InvalidCount++;
    }
}
